<template>
  <div class="future">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="- 没有更多电影了 -"
      @load="onLoad"
    >
      <van-card
        v-for="item in list"
        :key="item.filmId"
        class="box"
        @click="mdetail(item.filmId)"
      >
        <template #thumb>
          <img :src="item.poster" alt="" class="filmImg" />
        </template>
        <template #title>
          <div class="fileName">
            {{ item.name }} <span class="item">{{ item.item.name }}</span>
          </div>
          <div class="detail">
            <div class="label , actors">
              主演：{{ item.actors | getActors(item.actors) }}
            </div>
            <div class="label">上映日期：{{ item.premiereAt | riqi }}</div>
          </div>
        </template>
        <template #tags>
          <van-tag plain type="danger" class="buy">预购</van-tag>
        </template>
      </van-card>
    </van-list>
  </div>
</template>

<script>
import api from '@/api'
export default {
  data() {
    return {
      list: [],
      pageNum: 1,
      loading: false,
      finished: false
    }
  },
  methods: {
    onLoad() {
      this.$http.get(api.getFuture + '?pageNum=' + this.pageNum).then((res) => {
        console.log(res)
        this.list.push(...res.data.films)
        if (res.status === 0 && res.msg === 'ok') {
          if (this.list.length < res.data.total) {
            this.pageNum++
          } else {
            this.finished = true
          }
          this.loading = false
        }
      })
    },
    mdetail(id) {
      this.$store.commit('filmId', id)
      this.$router.push('/movie/mdetail')
    }
  },
  filters: {
    getActors(arr) {
      if (arr) {
        const brr = arr.map((item) => item.name)
        return brr.join(' ')
      } else {
        return '暂无主演'
      }
    },
    riqi(val) {
      const b = val * 1000
      const data = new Date(b)
      const month = data.getMonth() + 1
      const ri = data.getDate()
      const zhou = data.getDay()
      const arr = ['一', '二', '三', '四', '五', '六', '日']
      const z = arr[zhou - 1]
      return ' 周' + z + ' ' + month + '月' + ri + '日'
    }
  }
}
</script>

<style lang='scss' scoped>
.future {
  padding-bottom: 40px;
  .van-card {
    width: 100%;
    margin: 0 auto;
    .filmImg {
      width: 66px;
      margin: 0 5px;
    }
    .fileName {
      color: #191a1b;
      font-size: 16px;
      height: 22px;
      line-height: 22px;
      margin-right: 5px;
      .item {
        display: inline-block;
        font-size: 9px;
        color: #fff;
        background-color: #d2d6dc;
        height: 16px;
        line-height: 16px;
        padding: 1px 2px;
        border-radius: 2px;
        margin-left: 3px;
      }
    }
    .buy {
      position: absolute;
      right: 0;
      bottom: 40px;
    }
    .detail {
      font-size: 13px;
      margin-top: 5px;
      .actors {
        width: 140px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      div {
        margin: 3px 0;
      }
    }
  }
}
</style>
